﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Web.Mvc;
using Gman.Entity.Entities;
using System.Collections.Generic;
using Gman.WebApp.ServiceControllers;

namespace Gman.WebApp.Models
{
    public class SedeModel : BaseModel
    {
        public Guid? ID { get; set; }
        public string Action { get; set; }
        public SedeBE Sede { get; private set; }
        public List<PersonalModel> Personales { get; set; }

        public SelectList Departamento { get; set; }
        public SelectList Provincia { get; set; }
        public SelectList Distrito { get; set; }
        public UbigeoBE Ubigeo { get; set; }

        public SedeModel()
        {
            Sede = new SedeBE();
        }

        public SedeModel(SedeBE sede)
        {
            ID = Guid.NewGuid();
            Sede = sede;
        }

        public SedeModel(SedeBE sede, UbigeoBE Ubi)
        {
            ID = Guid.NewGuid();
            Sede = sede;
            Ubigeo = Ubi;
            Departamento = ListarDepartamentos();
            Provincia = ListarProvincias();
            Distrito = ListarDistritos();
            Personales = new List<PersonalModel>();
        }

        public ValidationBase Validator { get; set; }
        public List<KeyValuePair<string, string>> ValidationList = new List<KeyValuePair<string, string>>();
        public List<KeyValuePair<string, bool>> PropertyVisibilityList = new List<KeyValuePair<string, bool>>();

        public ToolBarModel ToolBar { get; set; }

        private SelectList ListarDepartamentos()
        {
            List<SelectListItem> listItem = new List<SelectListItem>();
            SedeBE sede = new SedeBE();
            listItem.Add(seleccione);
            listItem.AddRange(new SelectList(GeneralServiceController.ListarUbigeo(new UbigeoBE(), 1), "CodDpto", "DescUbigeo"));

            return new SelectList(listItem, "Value", "Text");
        }

        private SelectList ListarProvincias()
        {
            List<SelectListItem> listItem = new List<SelectListItem>();
            SedeBE sede = new SedeBE();
            listItem.Add(seleccione);
            listItem.AddRange(new SelectList(GeneralServiceController.ListarUbigeo(new UbigeoBE(), 4), "CodProv", "DescUbigeo"));

            return new SelectList(listItem, "Value", "Text");
        }

        private SelectList ListarDistritos()
        {
            List<SelectListItem> listItem = new List<SelectListItem>();
            SedeBE sede = new SedeBE();
            listItem.Add(seleccione);
            listItem.AddRange(new SelectList(GeneralServiceController.ListarUbigeo(new UbigeoBE(), 4), "CodDist", "DescUbigeo"));

            return new SelectList(listItem, "Value", "Text");
        }
    }
}
